package com.my.mytest.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;
import android.util.DisplayMetrics;

import com.my.mytest.R;
import com.my.mytest.adapter.ItemAllAnimAdapter;
import com.my.mytest.adapter.ItemAnimAdapter;
import com.my.mytest.bean.ImageData;
import com.my.mytest.util.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ItemAllAnimActivity extends AppCompatActivity {
    private RecyclerView rv_iaa;

    private static final Integer[] CATS = new Integer[]{
            R.mipmap.p1,
            R.mipmap.p2,
            R.mipmap.p3,
            R.mipmap.p4,
            R.mipmap.p5,
            R.mipmap.p6,
            R.mipmap.p7,
            R.mipmap.p8,
            R.mipmap.p9,
            R.mipmap.p10,
            R.mipmap.p11,
            R.mipmap.p12,
            R.mipmap.p13,
            R.mipmap.p14,
            R.mipmap.p15,
            R.mipmap.p16,
            R.mipmap.p17,
            R.mipmap.p18,
            R.mipmap.p19,
            R.mipmap.p20,
            R.mipmap.p21,
    };

    private List<Integer> data;
    private ItemAllAnimAdapter adapter;
    private List<ImageData> imgData = new ArrayList<>();
    private DisplayMetrics metrics;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item_all_anim);
        initData();
        initView();
    }

    private void initData() {
        data = Arrays.asList(CATS);
    }

    private void initView() {
        rv_iaa = findViewById(R.id.rv_iaa);

        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        rv_iaa.setLayoutManager(layoutManager);
        rv_iaa.addItemDecoration(new SpaceItemDecoration(this, 64, 2));// 添加分割线


        adapter = new ItemAllAnimAdapter(this);
        rv_iaa.setAdapter(adapter);

        metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        ImageData dd = new ImageData(0, 0);
        dd.setHeader(true);
        imgData.add(dd);

        for (int i = 0; i < data.size(); i++) {
            imgData.add(new ImageData(data.get(i), 0));
        }

        adapter.setData(imgData, 1);

    }
}